
const app = getApp();

export const reportMixin = {

  onPullDownRefresh() {
    let type = this.data.item.source.type;
    if(type == 'report'){return}
    this.onList(1);
  },
  onReachBottom() {
    let type = this.data.item.source.type;
    if(type == 'report'){return}
    const isFinlishLoad = this.data.isFinlishLoad;
    if(isFinlishLoad){return}
    
    let page = this.data.currentPage;
    this.onList(page+1);
  },
  async initShowNode(){
      try {
        const response = await this.$_server("task/detail", {
          data: {
            taskId: this.data.id,
          },
        });
        let {
          data
        } = response;
        if (data.code !== 200) {
          throw data;
        }
        let stepsData = [];
        let reviewData = [];
        for(let i = (data.data.length<=5?0:data.data.length-5);i<data.data.length;i++){
          const element = data.data[i];
          let node = "";
          let type = "";
          if(element.category == "send"){
            node = "发起"
          }else if(element.category == "handle"){
            node = "填报"
          }if(element.category == "approval"){
            node = "审批"
          }
          if(element.approvalStatus){
            if(element.approvalStatus==1){
              type = "通过"
            }else{
              type = "驳回"
            }
            if(element.reason){
              reviewData.push({
                name:element.assignee,
                nodeApprovalStatus:element.approvalStatus,
                reason : element.reason,
              })
            }
          } 
          stepsData.push({
            text:"("+element.assignee+")",
            desc:node+type
          })  
        }
        this.setData({
          reviewData:reviewData,
          steps: stepsData
        })
      } catch (error) {
        console.log("error",error)
        if (error.message) {
          wx.showToast({
            mask: true,
            title: error.message,
            icon: "none",
            duration: 2000,
          });
        } else {
          throw error;
        }
      }
  },
  //表单上报
  async getDeclareDetails(){
    let item = this.data.item.source;
    const response = await this.$_server("declare/detail", {
      params: {
          id: "?formId=" + item.formId + "&dataFormId=" + item.dataId,
      },
      });
      let { data } = response;
      if(data.code != 200){
        return;
      }
      let info = data.data.info;
      this.setData({
        info:info
      })
      console.log(info);

  }





}